

<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>toydata.PositionalList &mdash; ToyData 1.0 documentation</title>
  

  
  
  
  

  
  <script type="text/javascript" src="../../_static/js/modernizr.min.js"></script>
  
    
      <script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script>
        <script type="text/javascript" src="../../_static/jquery.js"></script>
        <script type="text/javascript" src="../../_static/underscore.js"></script>
        <script type="text/javascript" src="../../_static/doctools.js"></script>
        <script type="text/javascript" src="../../_static/language_data.js"></script>
    
    <script type="text/javascript" src="../../_static/js/theme.js"></script>

    

  
  <link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
    <link rel="index" title="Index" href="../../genindex.html" />
    <link rel="search" title="Search" href="../../search.html" /> 
</head>

<body class="wy-body-for-nav">

   
  <div class="wy-grid-for-nav">
    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >
          

          
            <a href="../../index.html" class="icon icon-home"> ToyData
          

          
          </a>

          
            
            
              <div class="version">
                1.0
              </div>
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <p class="caption"><span class="caption-text">Contents:</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../Intro.html">Introductions</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../Overview.html">Overview</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../modules.html">toydata</a></li>
</ul>

            
          
        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../../index.html">ToyData</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../../index.html">Docs</a> &raquo;</li>
        
          <li><a href="../index.html">Module code</a> &raquo;</li>
        
      <li>toydata.PositionalList</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <h1>Source code for toydata.PositionalList</h1><div class="highlight"><pre>
<span></span><span class="k">class</span> <span class="nc">_DoublyLinkedBase</span><span class="p">:</span>
    <span class="sd">&quot;&quot;&quot;A base class providing a doubly linked list representation&quot;&quot;&quot;</span>

    <span class="k">class</span> <span class="nc">_Node</span><span class="p">:</span>
        <span class="sd">&quot;&quot;&quot;Lightweight, nonpublic class for storing a doubly linked node&quot;&quot;&quot;</span>
        <span class="vm">__slots__</span> <span class="o">=</span> <span class="s1">&#39;_element&#39;</span><span class="p">,</span> <span class="s1">&#39;_prev&#39;</span><span class="p">,</span> <span class="s1">&#39;_next&#39;</span>

        <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">element</span><span class="p">,</span> <span class="n">prev</span><span class="p">,</span> <span class="nb">next</span><span class="p">):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_element</span> <span class="o">=</span> <span class="n">element</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_prev</span> <span class="o">=</span> <span class="n">prev</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_next</span> <span class="o">=</span> <span class="nb">next</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Create an empty list&quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_header</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_Node</span><span class="p">(</span><span class="kc">None</span><span class="p">,</span> <span class="kc">None</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_tailer</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_Node</span><span class="p">(</span><span class="kc">None</span><span class="p">,</span> <span class="kc">None</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_header</span><span class="o">.</span><span class="n">_next</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_tailer</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_tailer</span><span class="o">.</span><span class="n">_prev</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_header</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_size</span> <span class="o">=</span> <span class="mi">0</span>

    <span class="k">def</span> <span class="fm">__len__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Return the number of element in the list&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_size</span>

    <span class="k">def</span> <span class="nf">is_empty</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Return True if the list is empty&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_size</span> <span class="o">==</span> <span class="mi">0</span>

    <span class="k">def</span> <span class="nf">_insert_between</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">e</span><span class="p">,</span> <span class="n">predecessor</span><span class="p">,</span> <span class="n">successor</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Add element e between two existing nodes and return  new node&quot;&quot;&quot;</span>
        <span class="n">newest</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_Node</span><span class="p">(</span><span class="n">e</span><span class="p">,</span> <span class="n">predecessor</span><span class="p">,</span> <span class="n">successor</span><span class="p">)</span>
        <span class="n">predecessor</span><span class="o">.</span><span class="n">_next</span> <span class="o">=</span> <span class="n">newest</span>
        <span class="n">successor</span><span class="o">.</span><span class="n">_prev</span> <span class="o">=</span> <span class="n">newest</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_size</span> <span class="o">+=</span> <span class="mi">1</span>
        <span class="k">return</span> <span class="n">newest</span>

    <span class="k">def</span> <span class="nf">_delete_node</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">node</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Delete nonsentinel node from the list and return its element&quot;&quot;&quot;</span>
        <span class="n">predecessor</span> <span class="o">=</span> <span class="n">node</span><span class="o">.</span><span class="n">_prev</span>
        <span class="n">successor</span> <span class="o">=</span> <span class="n">node</span><span class="o">.</span><span class="n">_next</span>
        <span class="n">predecessor</span><span class="o">.</span><span class="n">_next</span> <span class="o">=</span> <span class="n">successor</span>
        <span class="n">successor</span><span class="o">.</span><span class="n">_prev</span> <span class="o">=</span> <span class="n">predecessor</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_size</span> <span class="o">-=</span> <span class="mi">1</span>
        <span class="c1"># record deleted element</span>
        <span class="n">element</span> <span class="o">=</span> <span class="n">node</span><span class="o">.</span><span class="n">_element</span>
        <span class="c1"># deprecate node</span>
        <span class="n">node</span><span class="o">.</span><span class="n">_prev</span> <span class="o">=</span> <span class="n">node</span><span class="o">.</span><span class="n">_next</span> <span class="o">=</span> <span class="n">node</span><span class="o">.</span><span class="n">_element</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="k">return</span> <span class="n">element</span>


<div class="viewcode-block" id="PositionalList"><a class="viewcode-back" href="../../toydata.html#toydata.PositionalList.PositionalList">[docs]</a><span class="k">class</span> <span class="nc">PositionalList</span><span class="p">(</span><span class="n">_DoublyLinkedBase</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;A sequential container of elements allowing positional access&quot;&quot;&quot;</span>

    <span class="c1"># Nested class</span>
<div class="viewcode-block" id="PositionalList.Position"><a class="viewcode-back" href="../../toydata.html#toydata.PositionalList.PositionalList.Position">[docs]</a>    <span class="k">class</span> <span class="nc">Position</span><span class="p">:</span>
        <span class="sd">&quot;&quot;&quot;A abstraction representing the location of a single element&quot;&quot;&quot;</span>

        <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">container</span><span class="p">,</span> <span class="n">node</span><span class="p">):</span>
            <span class="sd">&quot;&quot;&quot;Construct should not be invoked by user&quot;&quot;&quot;</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_container</span> <span class="o">=</span> <span class="n">container</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_node</span> <span class="o">=</span> <span class="n">node</span>

<div class="viewcode-block" id="PositionalList.Position.element"><a class="viewcode-back" href="../../toydata.html#toydata.PositionalList.PositionalList.Position.element">[docs]</a>        <span class="k">def</span> <span class="nf">element</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
            <span class="sd">&quot;&quot;&quot;Return the element store at this Position&quot;&quot;&quot;</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_node</span><span class="o">.</span><span class="n">_element</span></div>

        <span class="k">def</span> <span class="fm">__eq__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">):</span>
            <span class="sd">&quot;&quot;&quot;Return True if other is a Position representing the same</span>
<span class="sd">            location&quot;&quot;&quot;</span>
            <span class="k">return</span> <span class="nb">type</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="ow">is</span> <span class="nb">type</span><span class="p">(</span><span class="n">other</span><span class="p">)</span> <span class="ow">and</span> <span class="n">other</span><span class="o">.</span><span class="n">_node</span> <span class="ow">is</span> <span class="bp">self</span><span class="o">.</span><span class="n">_node</span>

        <span class="k">def</span> <span class="fm">__ne__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">other</span><span class="p">):</span>
            <span class="sd">&quot;&quot;&quot;Return True if other does not represent the same location&quot;&quot;&quot;</span>
            <span class="k">return</span> <span class="ow">not</span> <span class="p">(</span><span class="bp">self</span> <span class="o">==</span> <span class="n">other</span><span class="p">)</span></div>

    <span class="c1"># utility method</span>
    <span class="k">def</span> <span class="nf">_validate</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">p</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Return position&#39;s node, or raise appropriate error if invalid&quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">p</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">Position</span><span class="p">):</span>
            <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span><span class="s1">&#39;P must be proper Position type&#39;</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">p</span><span class="o">.</span><span class="n">_container</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">self</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;p does not belong to this container&#39;</span><span class="p">)</span>
        <span class="c1"># convention for depreated nodes</span>
        <span class="k">if</span> <span class="n">p</span><span class="o">.</span><span class="n">_node</span><span class="o">.</span><span class="n">_next</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;p is no longer valid&#39;</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">p</span><span class="o">.</span><span class="n">_node</span>

    <span class="k">def</span> <span class="nf">_make_position</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">node</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Return Position instance for given nodee(or None if sentinel)&quot;&quot;&quot;</span>
        <span class="c1"># boundary violation</span>
        <span class="k">if</span> <span class="n">node</span> <span class="ow">is</span> <span class="bp">self</span><span class="o">.</span><span class="n">_header</span> <span class="ow">or</span> <span class="n">node</span> <span class="ow">is</span> <span class="bp">self</span><span class="o">.</span><span class="n">_tailer</span><span class="p">:</span>
            <span class="k">return</span> <span class="kc">None</span>
        <span class="c1"># legitimate position</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">Position</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">node</span><span class="p">)</span>

    <span class="c1"># Accessors</span>
<div class="viewcode-block" id="PositionalList.first"><a class="viewcode-back" href="../../toydata.html#toydata.PositionalList.PositionalList.first">[docs]</a>    <span class="k">def</span> <span class="nf">first</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Return the first Position in the list(or None if list is empty)&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_make_position</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_header</span><span class="o">.</span><span class="n">_next</span><span class="p">)</span></div>

<div class="viewcode-block" id="PositionalList.last"><a class="viewcode-back" href="../../toydata.html#toydata.PositionalList.PositionalList.last">[docs]</a>    <span class="k">def</span> <span class="nf">last</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Return the last Position in the list(or None if list is empty)&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_make_position</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_tailer</span><span class="o">.</span><span class="n">_prev</span><span class="p">)</span></div>

<div class="viewcode-block" id="PositionalList.before"><a class="viewcode-back" href="../../toydata.html#toydata.PositionalList.PositionalList.before">[docs]</a>    <span class="k">def</span> <span class="nf">before</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">p</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Return the Position just before Position p</span>
<span class="sd">        (or None if p is first)&quot;&quot;&quot;</span>
        <span class="n">node</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_validate</span><span class="p">(</span><span class="n">p</span><span class="p">)</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_make_position</span><span class="p">(</span><span class="n">node</span><span class="o">.</span><span class="n">_prev</span><span class="p">)</span></div>

<div class="viewcode-block" id="PositionalList.after"><a class="viewcode-back" href="../../toydata.html#toydata.PositionalList.PositionalList.after">[docs]</a>    <span class="k">def</span> <span class="nf">after</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">p</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Return the Position just after Position p</span>
<span class="sd">        (or None if p is last)&quot;&quot;&quot;</span>
        <span class="n">node</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_validate</span><span class="p">(</span><span class="n">p</span><span class="p">)</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_make_position</span><span class="p">(</span><span class="n">node</span><span class="o">.</span><span class="n">_next</span><span class="p">)</span></div>

    <span class="k">def</span> <span class="fm">__iter__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Generate a forward iteration of the elements of the list&quot;&quot;&quot;</span>
        <span class="n">cursor</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">first</span><span class="p">()</span>
        <span class="k">while</span> <span class="n">cursor</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">yield</span> <span class="n">cursor</span><span class="o">.</span><span class="n">element</span><span class="p">()</span>
            <span class="n">cursor</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">after</span><span class="p">(</span><span class="n">cursor</span><span class="p">)</span>

    <span class="c1"># mutators</span>
    <span class="k">def</span> <span class="nf">_insert_between</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">e</span><span class="p">,</span> <span class="n">predecessor</span><span class="p">,</span> <span class="n">successor</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Add element between exsiting nodes and return new Position&quot;&quot;&quot;</span>
        <span class="n">node</span> <span class="o">=</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">_insert_between</span><span class="p">(</span><span class="n">e</span><span class="p">,</span> <span class="n">predecessor</span><span class="p">,</span> <span class="n">successor</span><span class="p">)</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_make_position</span><span class="p">(</span><span class="n">node</span><span class="p">)</span>

<div class="viewcode-block" id="PositionalList.add_first"><a class="viewcode-back" href="../../toydata.html#toydata.PositionalList.PositionalList.add_first">[docs]</a>    <span class="k">def</span> <span class="nf">add_first</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">e</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Insert element e at the front of the list and return new Pos&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_insert_between</span><span class="p">(</span><span class="n">e</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_header</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_header</span><span class="o">.</span><span class="n">_next</span><span class="p">)</span></div>

<div class="viewcode-block" id="PositionalList.add_last"><a class="viewcode-back" href="../../toydata.html#toydata.PositionalList.PositionalList.add_last">[docs]</a>    <span class="k">def</span> <span class="nf">add_last</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">e</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Insert element e at the back of the list and return new Pos&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_insert_between</span><span class="p">(</span><span class="n">e</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_tailer</span><span class="o">.</span><span class="n">_prev</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_tailer</span><span class="p">)</span></div>

<div class="viewcode-block" id="PositionalList.add_before"><a class="viewcode-back" href="../../toydata.html#toydata.PositionalList.PositionalList.add_before">[docs]</a>    <span class="k">def</span> <span class="nf">add_before</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">p</span><span class="p">,</span> <span class="n">e</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Insert element e into list before Position p and return new Pos&quot;&quot;&quot;</span>
        <span class="n">original</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_validate</span><span class="p">(</span><span class="n">p</span><span class="p">)</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_insert_between</span><span class="p">(</span><span class="n">e</span><span class="p">,</span> <span class="n">original</span><span class="o">.</span><span class="n">_prev</span><span class="p">,</span> <span class="n">original</span><span class="p">)</span></div>

<div class="viewcode-block" id="PositionalList.add_after"><a class="viewcode-back" href="../../toydata.html#toydata.PositionalList.PositionalList.add_after">[docs]</a>    <span class="k">def</span> <span class="nf">add_after</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">p</span><span class="p">,</span> <span class="n">e</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Insert element e into list after Position p and return new Pos&quot;&quot;&quot;</span>
        <span class="n">original</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_validate</span><span class="p">(</span><span class="n">p</span><span class="p">)</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_insert_between</span><span class="p">(</span><span class="n">e</span><span class="p">,</span> <span class="n">original</span><span class="p">,</span> <span class="n">original</span><span class="o">.</span><span class="n">_next</span><span class="p">)</span></div>

<div class="viewcode-block" id="PositionalList.delete"><a class="viewcode-back" href="../../toydata.html#toydata.PositionalList.PositionalList.delete">[docs]</a>    <span class="k">def</span> <span class="nf">delete</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">p</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Remove and return the element at Position p&quot;&quot;&quot;</span>
        <span class="n">original</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_validate</span><span class="p">(</span><span class="n">p</span><span class="p">)</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_delete_node</span><span class="p">(</span><span class="n">original</span><span class="p">)</span></div>

<div class="viewcode-block" id="PositionalList.replace"><a class="viewcode-back" href="../../toydata.html#toydata.PositionalList.PositionalList.replace">[docs]</a>    <span class="k">def</span> <span class="nf">replace</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">p</span><span class="p">,</span> <span class="n">e</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Replace the element at Position p with e.</span>
<span class="sd">        Return the element formerly at Position p&quot;&quot;&quot;</span>
        <span class="n">original</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_validate</span><span class="p">(</span><span class="n">p</span><span class="p">)</span>
        <span class="n">old_value</span> <span class="o">=</span> <span class="n">original</span><span class="o">.</span><span class="n">_element</span>
        <span class="n">original</span><span class="o">.</span><span class="n">_element</span> <span class="o">=</span> <span class="n">e</span>
        <span class="k">return</span> <span class="n">old_value</span></div></div>
</pre></div>

           </div>
           
          </div>
          <footer>
  

  <hr/>

  <div role="contentinfo">
    <p>
        &copy; Copyright 2019, Xiangzhuang Shen

    </p>
  </div>
  Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>

        </div>
      </div>

    </section>

  </div>
  


  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>

  
  
    
   

</body>
</html>